package com.xxgc.eow.service.impl;

import com.xxgc.eow.entity.Follow;
import com.xxgc.eow.mapper.FollowMapper;
import com.xxgc.eow.service.IFollowService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 关注表 服务实现类
 * </p>
 *
 * @author Mr.Abel
 * @since 2023-05-29
 */
@Service
public class FollowServiceImpl extends ServiceImpl<FollowMapper, Follow> implements IFollowService {


    @Resource
    private FollowMapper followMapper;

    @Override
    public int insertFollow(Follow follow) {
        Date date = new Date();
        Instant instant = date.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
        follow.setCreateTime(localDateTime);
        return followMapper.insertFollow(follow);
    }

    @Override
    public Follow selectByFollow(Follow follow) {
        return followMapper.selectByFollow(follow);
    }

    @Override
    public int delFollow(Follow follow) {
        Date date = new Date();
        Instant instant = date.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
        follow.setDestroyTime(localDateTime);
        return followMapper.delFollow(follow);
    }

    @Override
    public List<Integer> selectByUserFollowId(int userFollowId) {
        return followMapper.selectByUserFollowId(userFollowId);
    }

    @Override
    public Integer getFollowCount(Integer userId) {
        Integer num = followMapper.selectFollowCount(userId);
        if(num == null){
            return 0;
        }
        return num;
    }

    @Override
    public Integer getFansCount(Integer userId) {
        Integer num = followMapper.selectFansCount(userId);
        if(num == null){
            return 0;
        }
        return num;
    }

    @Override
    public List<Integer> selectByUserId(int userId) {
        return followMapper.selectByUserId(userId);
    }

    @Override
    public List<Follow> selectAll() {
        return followMapper.selectAll();
    }
}
